import {
  Injectable,
  NestInterceptor,
  ExecutionContext,
  HttpStatus,
  CallHandler
} from '@nestjs/common'
import dayjs from 'dayjs'
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'

@Injectable()
export class ResponseInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    return next.handle().pipe(
      map(data => ({
        timestamp: dayjs().format('YYYY-MM-DD HH:mm:ss.SSS'),
        status: HttpStatus.OK,
        message: 'success',
        data
      }))
    )
  }
}
